package com.group.integration.controller.back;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.group.integration.controller.back.vo.DiscountResultVO;
import com.group.integration.repository.entity.Coupon;
import com.group.integration.service.DifferentCouponService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * coupon test
 *
 * @author xiaoma
 * @date 2024-07-04 16:52
 **/
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/demo")
public class MapFutureDemoController {

    private final DifferentCouponService differentCouponService;

    /**
     * We use the Map and the Future interface to replace the Strategy Design
     * Pattern
     *
     * @param type the type of the coupon
     * @return
     * @throws JsonProcessingException
     */
    @GetMapping("/getDifferentCoupon")
    public ResponseEntity<List<DiscountResultVO>> getDifferentCouponById(String type) throws JsonProcessingException {

        List<DiscountResultVO> list = differentCouponService.getDifferentCouponByType(type);
        return ResponseEntity.ok(list);
    }

    /**
     * 
     * add the coupon information to the database
     * 
     * @param coupon
     * @return
     */
    @PostMapping("/addCoupon")
    public ResponseEntity<Coupon> postMethodName(@RequestBody Coupon coupon) {

        Coupon entity = differentCouponService.addCoupon(coupon);
        return ResponseEntity.ok(entity);
    }

}
